// // Copyright (c) 2009 All Right Reserved // // Stephen Toub // stoub@microsoft.com // 2009-01-01 // Contains ... using System; using System.Globalization; using System.IO; using System.Text; using JetBrains.Annotations; namespace LargoCommon.Midi { /// An SMPTE offset meta event message. [Serializable] public sealed class MetaTimeCodeOffset : MetaEvent { #region Fields /// The meta id for this event. private const byte EventMetaId = 0x54; /// The status byte for TimeCodeOffset (?!). private const byte StatusByte = 0x05; #endregion #region Constructors /// Initializes a new instance of the MetaTimeCodeOffset class. /// The amount of time before this event. /// Hours for the event. /// Minutes for the event. /// Seconds for the event. /// Frames for the event. /// Fractional frames for the event. public MetaTimeCodeOffset( long deltaTime, byte givenHours, byte givenMinutes, byte givenSeconds, byte givenFrames, byte givenFractionalFrames) : base(deltaTime, EventMetaId) { this.Hours = givenHours; this.Minutes = givenMinutes; this.Seconds = givenSeconds; this.Frames = givenFrames; this.FractionalFrames = givenFractionalFrames; } /// Initializes a new instance of the MetaTimeCodeOffset class. /// The amount of time before this event. /// The ID of the meta event. [UsedImplicitly] public MetaTimeCodeOffset(long deltaTime, byte givenMetaEventId) : base(deltaTime, givenMetaEventId) { } #endregion #region Properties /// Gets the hours for the event. /// General musical property. private byte Hours { get; } /// Gets the minutes for the event. /// General musical property. private byte Minutes { get; } /// Gets the seconds for the event. /// General musical property. private byte Seconds { get; } /// Gets the frames for the event. /// General musical property. private byte Frames { get; } /// Gets the fractional frames for the event. /// General musical property. private byte FractionalFrames { get; } #endregion #region To String /// Generate a string representation of the event. /// A string representation of the event. public override string ToString() { var sb = new StringBuilder(); sb.Append(base.ToString()); sb.Append("\t"); sb.Append("0x"); sb.Append(this.Hours.ToString("X2", CultureInfo.CurrentCulture.NumberFormat)); sb.Append("\t"); sb.Append("0x"); sb.Append(this.Minutes.ToString("X2", CultureInfo.CurrentCulture.NumberFormat)); sb.Append("\t"); sb.Append("0x"); sb.Append(this.Seconds.ToString("X2", CultureInfo.CurrentCulture.NumberFormat)); sb.Append("\t"); sb.Append("0x"); sb.Append(this.Frames.ToString("X2", CultureInfo.CurrentCulture.NumberFormat)); sb.Append("\t"); sb.Append("0x"); sb.Append(this.FractionalFrames.ToString("X2", CultureInfo.CurrentCulture.NumberFormat)); return sb.ToString(); } #endregion #region Methods /// Write the event to the output stream. /// The stream to which the event should be written. public override void Write(Stream outputStream) { if (outputStream == null) { return; } //// Write out the base event information base.Write(outputStream); //// Event data outputStream.WriteByte(StatusByte); outputStream.WriteByte(this.Hours); outputStream.WriteByte(this.Minutes); outputStream.WriteByte(this.Seconds); outputStream.WriteByte(this.Frames); outputStream.WriteByte(this.FractionalFrames); } #endregion } }